package com.example.lotterysystem.service.mq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
import static com.example.lotterysystem.common.config.DirectRabbitConfig.*;

@Component
@Slf4j
@RabbitListener(queues = DLX_QUEUE_NAME)
public class DixReceiver {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RabbitHandler
    public void process(Map<String,String> message) throws Exception {
        //死信队列得处理方法
        log.info("开始处理异常消息!");
        rabbitTemplate.convertAndSend(EXCHANGE_NAME, ROUTING, message);

        //该流程是有问题得, 在这里只是为了演示处理过程中发生得异常
        //正确得流程:

    }
}
